#include <fcntl.h>
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <sys/types.h>

#include "bloques.h"
#include "bitmaps.h"
#include "constants.h"
#include "ext2_fs.h"
#include "ext2_types.h"

int main(int argc, char **argv){
	int fd;
	char *address;

	if(argc != 2){
		printf("Numero de argumentos erroneos en leer_sf.c \n");
		exit(-1);
	}
	
	fd = open(argv[1], O_RDONLY);
	if (fd == -1) {
		perror("Imposible abrir archivo");
		exit(-1);
	}

	address = mmap(0, BLOCK_SIZE * BLOCKS_COUNT, PROT_READ, MAP_SHARED, fd, 0);


	ext2_super_block *super_block = readSuperBlock(address);
	int cant_grupos = ceil((float)EXT2_BLOCKS_COUNT(super_block) /
			(float)EXT2_BLOCKS_PER_GROUP(super_block));

	int groupId;
	for(groupId = 0; groupId < cant_grupos; groupId++) {
		ext2_group_desc *group_desc = readGroupDescriptor(address, groupId);
		leerTablaInodos(address, groupId);
		// print debug information
		free(group_desc);
	}

	return EXIT_SUCCESS;
}
